// system.h 
//	All global variables used in Nachos are defined here.
//
// Copyright (c) 1992-1993 The Regents of the University of California.
// All rights reserved.  See copyright.h for copyright notice and limitation 
// of liability and disclaimer of warranty provisions.

#ifndef SYSTEM_H
#define SYSTEM_H

#include "copyright.h"
#include "utility.h"
#include "thread.h"
#include "scheduler.h"
#include "interrupt.h"
#include "stats.h"
#include "timer.h"
#include "synch.h"

#define MAX_LOCKS 400
#define MAX_CONDITIONS 800

#ifdef USER_PROGRAM
//#ifdef CHANGED
#include "addrspace.h"
#include "processtable.h"
struct KernelLock
{
	Lock* lock;
	AddrSpace* addrSpace;
	bool isToBeDeleted;
};

struct KernelCondition
{
	Condition* condition;
	AddrSpace* addrSpace;
	bool isToBeDeleted;
};
//#endif //CHANGED
#endif //USER_PROGRAM

// Initialization and cleanup routines
extern void Initialize(int argc, char **argv); 	// Initialization,
						// called before anything else
extern void Cleanup();				// Cleanup, called when
						// Nachos is done.

extern Thread *currentThread;			// the thread holding the CPU
extern Thread *threadToBeDestroyed;  		// the thread that just finished
extern Scheduler *scheduler;			// the ready list
extern Interrupt *interrupt;			// interrupt status
extern Statistics *stats;			// performance metrics
extern Timer *timer;				// the hardware alarm clock

#ifdef USER_PROGRAM
#include "machine.h"
extern Machine* machine;	// user program memory and registers
//#ifdef CHANGED
#include "processtable.h"
extern BitMap* memoryMap;
extern Lock* memoryMapLock;

extern Lock* kernelLocksConditionsLock;
extern BitMap* kernelLocksMap;
extern KernelLock kernelLocks[MAX_LOCKS];
extern Lock* kernelLocksLock;
extern BitMap* kernelConditionsMap;
extern KernelCondition kernelConditions[MAX_CONDITIONS];
extern Lock* kernelConditionsLock;

extern ProcessTable* processTable;

extern Lock* machineLock;
extern Lock* processTableLock;
extern Lock* syscallLock;
extern Lock* execLock;
extern Lock* forkLock;
extern unsigned int currentTLB;

/*********************Project3  step2 IPT *********************/
#include "ipt.h"

extern Lock *iptLock;
extern IPTEntry *ipt;
/*********************End Project3  step2 IPT *****************/

//#endif // CHANGED
#endif

#ifdef FILESYS_NEEDED 		// FILESYS or FILESYS_STUB 
#include "filesys.h"
extern FileSystem  *fileSystem;
#endif

#ifdef FILESYS
#include "synchdisk.h"
extern SynchDisk   *synchDisk;
#endif

#ifdef NETWORK
#include "post.h"
extern PostOffice* postOffice;
extern Thread* mailboxs[101];
#endif

#endif // SYSTEM_H
